#Use close_all of watir,sometimes the IE could not be closed
#Or we could terminate the process of IE,like the method below,
require 'win32ole'
#Returns the number of windows processes running with the specified name.
def close_ie
  mgmt = WIN32OLE.connect('winmgmts:\\\\.')
  processes = mgmt.instancesof("win32_process")
  processes.each do |process|
    puts process
  if process.name == "iexplore.exe" then
    process.terminated()
  end
end
end
#Use Dom to find the element of Page
ie = Watri::IE.start("www.google.com")
def find_tag_by_text(ie,textName)
  all_elements = ie.document.body.all
  all_element.each do |object|
    if object.innerText.match(textName)
      flag = false
      all_children = object.children
      #if subobject matched,then quit,and flag become true
      all_children.each do |child|
        if child.innerText.match(textName)
          flag = true
          break
        else
          next
        end
      end
      #when subnode do not match with text, then it is end.
      unless flag
        puts object.tagName
        break
      end
    end
  end
end
find_tag_by_text(ie,"search")
#if want to get the parent node of the node
#~ unless flag
  #~ parent = object.parentElement
  #~ puts parent.tagName
  #~ break
#~ end
#if want to get the subnode of the node
#~ unless flag
  #~ children = object.children
  #~ puts "___________"
  #~ children.each do |child|
    #~ puts child.tagName
  #~ break
#~ end

#use watir to get the attribute value of css
#require 'watir'
#~ def test
  #~ @ie = Watir::IE.attach(:url,/www.google.com/)
  #~ thislink = @ie.link(:text,'Google')
  #~ puts thislink.document.currentStyle.fontsize
#~ end

#~ test

#use command line prompt to execute ruby,which need to pass parameter with global variable ARGV
#~ def hello(a)
  #~ puts a
#~ end
#~ hello(ARGV)

#Use ruby to clear IE cookie
def kill_all_cookie(dir="C:\\Documents and Settings\\" + ENV['USERNAME'] + "\\Local Settings\\Temporary Internet Files")
  require 'fileutils'
  FileUtils.rm_rf dir
end

#~ #Get IE Version
#~ #require 'watir'
#~ ie = Watir::IE.attach(:url,/daily/)
#~ n = ie.document.invoke('parentWindow').navigator.appVersion
#~ m = /MSIE\s(.*?);/.match(n)
#~ if m[1]=="6.0" then
  #~ puts "IE version = 6.0"
  #~ else
    #~ puts "IE version = 7.0"
  #~ end
  
#~ #Look up in Register
#~ run = .reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\"\/v version".

